package com.imooc.reader.portal.controller;

import com.imooc.reader.portal.dto.ResponseDTO;
import com.imooc.reader.portal.entity.Evaluation;
import com.imooc.reader.portal.service.EvaluationService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/evaluations")
public class EvaluationController {
    @Resource
    private EvaluationService evaluationService;

    @GetMapping("")
    public ResponseDTO selectBookId(Long bookId) {
        List<Map> maps = evaluationService.selectBookId(bookId);
        return new ResponseDTO().put("list", maps);
    }

    @PostMapping("")
    public ResponseDTO evaluate(Long memberId, Long bookId, Integer score, String content) {
        Evaluation evaluation = evaluationService.evaluate(memberId, bookId, score, content);
        return new ResponseDTO().put("evaluation", evaluation);
    }
}
